﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataCore.Exeptions;

namespace DataCore.DomainObjects
{
    [Serializable]
    public class CurrentObject : DomainObject<long>
    {
        private MetaClass _metaClass;
        private List<Value> _values;

        public CurrentObject()
        {
            _values = new List<Value>();
        }

        public CurrentObject(MetaClass metaclass)
        {
            _metaClass = metaclass;
            _values = new List<Value>();
        }

        public MetaClass MetaClass
        {
            get { return _metaClass; }
            set { _metaClass = value; }
        }

        public List<Value> Values
        {
            get { return _values; }
            set { _values = value; }
        }

        public void AttacheValue(Value value)
        {
            if (_metaClass.ValidateAtribute(value.CurrentAttribute))
                _values.Add(value);
            else
                throw new MetaClassDontHeveThisAtributeExeption();
        }

        public Value GetByName(String name)
        {
            return _values.Single(x => x.CurrentAttribute.Name == name);
        }


        public override int GetHashCode()
        {
            int m = 23;
            return String.Concat(m * 17,
                _metaClass != null ? _metaClass.GetHashCode().ToString() : "0",
                _values != null ? _values.GetHashCode().ToString() : "0").GetHashCode();
        }

        public override void CopyFrom(DomainObject<long> T)
        {
            throw new NotImplementedException();
        }
    }
}
